package com.four.bmm.controller;

import com.four.bmm.entity.BlockItem;
import com.four.bmm.service.BlockService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/AdminAddBItemServlet")
public class AdminAddBItemServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String bitemname=request.getParameter("bitemname");
        System.out.println(bitemname);
        String blockid=request.getParameter("blockid");
        System.out.println(blockid);
        int blockId=Integer.parseInt(blockid);
        //Block block=new Block(blockid);
        System.out.println(blockid);
        System.out.println(bitemname);
        BlockItem blockItem=new BlockItem(bitemname,blockId);
        BlockService blockService=new BlockService();
        boolean result=blockService.addBlockItem(blockItem);
        if(result){
            response.sendRedirect("back/index.jsp");
        }else {
            request.setAttribute("msg","添加失败");
            response.sendRedirect("back/index.jsp");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
